import request from "../index";
import qs from "qs";

// 用户登陆
export const AdminLogin = (data: AdminLoginParams): RpI<LoginRespone> =>
  request.post("/admin/login", data);

// 获取当前登陆用户信息
export const AdminInfo = (): RpI<AdminLoginRes> => request.get("/admin/info");

// 根据用户名或姓名分页获取用户列表
export const AdminList = (params: AdminListParams): RpI<AdminListRespone> =>
  request.get("/admin/list", { params });

// 用户注册
export const AdminRegister = (umsAdminParam: AdminRegisteParam) =>
  request.post("/admin/register", umsAdminParam);

// 根据角色名称分页获取角色列表
export const RoleList = (params: AdminListParams): RpI<RoleListRes> =>
  request.get("/role/list", { params });

// 修改指定用户信息
export const AdminUpdate = (params: AdminListResponelist): RpI<unknown> =>
  request.post(`/admin/update/${params.id}`, params);

// 订单列表
export const orderList = (params: orderList): RpI<RoleListRes> =>
  request.get("/order/list", { params });
// 批量关闭订单
export const orderClose = (params: orderclose): RpI<outorderClose> =>
  request.post(`/order/update/close?ids=${params.ids}&note=${params.note}`);
// 批量删除订单
export const orderDelete = (parent: orderclose): RpI<outorderClose> =>
  request.post(`/order/delete?ids=${parent.ids}`);
// 获取订单设置
export const orderSetting = (id: number): RpI<ordersetting> =>
  request.get(`/orderSetting/${id}`);
//修改指定订单设置
export const editSetting = (paranm: ordersetting): RpI<outorderClose> =>
  request.post(`/orderSetting/update/${paranm.id}`, { paranm });

// 获取指定用户的角色
export const AdminRole = (params: number): RpI<IAssignRes[]> =>
  request.get(`/admin/role/${params}`);

// 给用户分配角色
export const AdminRoleUpdate = (params: IRoleUpdate): RpI<IAssignRes[]> =>
  request.post(`/admin/role/update`, qs.stringify(params));

// 查询所有后台资源分类
export const ResourceCategoryListAll = (): RpI<ICategoryListAllRes[]> =>
  request.get(`/resourceCategory/listAll`);

// 查询所有后台资源
export const ResourceListAll = (): RpI<ICategoryListAllRes[]> =>
  request.get(`/resource/listAll`);

// 获取角色相关资源
export const RoleListResource = (roleId: number): RpI<ICategoryListAllRes[]> =>
  request.get(`/role/listResource/${roleId}`);

// 给角色分配资源
export const RoleAllocResource = (
  params: IRoleAllocResourceParams
): RpI<ICategoryListAllRes[]> =>
  request.post(`/role/allocResource`, {}, { params });

// 分页查询后台菜单
export const MenuList = (params: AdminListParams): RpI<IMenuListRes> =>
  request.get(`/menu/list/${params.parentId}`, { params });
